<script setup lang="ts">
import MpHtml from 'mp-html/src/uni-app/components/mp-html/mp-html.vue'
import type { CustomerServiceDetail } from '@/types/api'
import { fetchCustomerServiceDetailAPI } from '@/apis/fetchCustomerServiceDetail'
import { useUserInfoStore } from '@/store/userInfo'

const userInfoStore = useUserInfoStore()

const detail = ref<CustomerServiceDetail>()

onLoad(async (options) => {
  if (!options?.id) {
    uni.showToast({ title: '获取数据失败', icon: 'none' })
    return
  }
  const res = await fetchCustomerServiceDetailAPI({
    id: options.id,
  }, userInfoStore.userInfo!.token!)
  if (res.data?.code !== 1) {
    uni.showToast({ title: res.data?.msg, icon: 'none' })
    return
  }
  detail.value = res.data.data
  uni.setNavigationBarTitle({ title: detail.value.title })
})
</script>

<template>
  <view class="min-h-screen bg-white p-24rpx">
    <MpHtml :content="detail?.content" />
  </view>
</template>

<route lang="yaml">
name: 'customerServiceDetail'
style:
  navigationBarBackgroundColor: white
</route>
